package purchasedepartment.purchaseorder.view;

import inventory.reports.view.CurrentStockReportView;
import inventory.reports.view.InwardReportView;
import inventory.reports.view.OutwardReportView;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import purchasedepartment.controller.PurchaseOrderFromIndentController;

import common.controller.PurchaseOrderController;
import common.view.PurchaseOrderView;

import viewframework.UIFrameWork;

public class PurchaseOrderMainView extends JPanel implements MouseListener
{
	private JToolBar toolBar;
	private JLabel[] leftMenu;
	private JLabel lblNewPurchaseOrder;
	private JLabel lblPurchaseOrderFromIndent;
	SpringLayout sl;

	public PurchaseOrderMainView() 
	{
		sl=new SpringLayout();
		setLayout(sl);
		
		toolBar = new JToolBar();
		toolBar.setBackground(SystemColor.inactiveCaption);
		toolBar.setBorder(null);
		toolBar.setOrientation(SwingConstants.VERTICAL);
		sl.putConstraint(sl.SOUTH, toolBar, 0, sl.SOUTH, this);
		sl.putConstraint(sl.NORTH, toolBar, 1, sl.NORTH, this);
		sl.putConstraint(sl.WEST, toolBar, 0, sl.WEST, this);
		sl.putConstraint(sl.EAST, toolBar, 180, sl.WEST, this);
		makeLeftMenu();
		addButtonsInToolBar();
		addButtonListener();
		add(toolBar);
	}
	
	private void makeLeftMenu()
	{
		leftMenu=new JLabel[2];
		
		lblNewPurchaseOrder=new JLabel("New Purchase Order",SwingConstants.CENTER);
		lblNewPurchaseOrder.setPreferredSize(new Dimension(72, 40));
		lblNewPurchaseOrder.setMinimumSize(new Dimension(180, 40));
		lblNewPurchaseOrder.setMaximumSize(new Dimension(180, 40));
		lblNewPurchaseOrder.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[0]=lblNewPurchaseOrder;
		
		lblPurchaseOrderFromIndent=new JLabel("Purchase Order From Indent",SwingConstants.CENTER);
		lblPurchaseOrderFromIndent.setPreferredSize(new Dimension(72, 40));
		lblPurchaseOrderFromIndent.setMinimumSize(new Dimension(180, 40));
		lblPurchaseOrderFromIndent.setMaximumSize(new Dimension(180, 40));
		lblPurchaseOrderFromIndent.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[1]=lblPurchaseOrderFromIndent;
		
		for(int k=0;k<leftMenu.length;k++)
			leftMenu[k].setBorder(null);
	}
	
	private void addButtonsInToolBar()
	{
		toolBar.add(lblNewPurchaseOrder);
		toolBar.addSeparator();
		toolBar.add(lblPurchaseOrderFromIndent);
		toolBar.addSeparator();
		
	}
	
	private void addButtonListener()
	{
		for(JLabel temp:this.leftMenu)
			 temp.addMouseListener(this);
	}

	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		if(arg0.getSource() instanceof JLabel)
		{
			JLabel label=(JLabel) arg0.getSource();
			
			if(label==lblNewPurchaseOrder)
			{
				PurchaseOrderView pov=new PurchaseOrderView();
				try {
					PurchaseOrderController cntrl = new PurchaseOrderController(pov,null);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				UIFrameWork.setReportComponent(sl,pov,this,2);
			}
				
			if(label==lblPurchaseOrderFromIndent)
			{
				PurchaseOrderFromIndentView pofiv=new PurchaseOrderFromIndentView();
				PurchaseOrderFromIndentController cntrl1=new PurchaseOrderFromIndentController(pofiv);
				UIFrameWork.setReportComponent(sl,pofiv, this,2);
			}
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
